package com.lg.utils.hutool.time;

import cn.hutool.core.date.*;

import java.util.Calendar;
import java.util.Date;

public class Base {
    public static void main(String[] args) {
        Date date0 = new Date();
        System.out.println(date0);


        //当前时间
        Date date = DateUtil.date();
        //当前时间
        Date date2 = DateUtil.date(Calendar.getInstance());
        //当前时间
        Date date3 = DateUtil.date(System.currentTimeMillis());
        //当前时间字符串，格式：yyyy-MM-dd HH:mm:ss
        String now = DateUtil.now();
        //当前日期字符串，格式：yyyy-MM-dd
        String today = DateUtil.today();
        System.out.println(date);

        String dateStr = "2017-03-01";
        Date date1 = DateUtil.parse(dateStr);
        System.out.println(date1);


        String dateStr11 = "2017-03-01";
        Date date11 = DateUtil.parse(dateStr11);
        //结果 2017/03/01
        String format = DateUtil.format(date11,"yyyy/MM/dd HH:mm:ss");
        //常用格式的格式化，结果：2017-03-01
        String formatDate = DateUtil.formatDate(date11);
        //结果：2017-03-01 00:00:00
        String formatDateTime = DateUtil.formatDateTime(date11);
        //结果：00:00:00
        String formatTime = DateUtil.formatTime(date11);

        System.out.println("------------next format----------");
        System.out.println(format);
        System.out.println(formatDate);
        System.out.println(formatDateTime);
        System.out.println(formatTime);

        System.out.println("------------get a part----------");
        //获得年的部分
        System.out.println(DateUtil.year(date));
        //获得月份，从0开始计数
        System.out.println(DateUtil.month(date));


        String dateStr22 = "2017-03-01 22:33:20";
        String dateStr33 = "2017-03-01 22:33:50";
        Date date22 = DateUtil.parse(dateStr22);

        System.out.println("------------before----------");
        Date date33 = DateUtil.parse(dateStr33);
        System.out.println(date22.before(date33));
        System.out.println(date22.after(date33));
        System.out.println(date22.equals(date33));
        System.out.println(DateUtil.between(date33, date22, DateUnit.MS));

        //结果：2017-03-03 22:33:23
        Date newDate = DateUtil.offset(date22, DateField.MILLISECOND, 2);
        //常用偏移，结果：2017-03-04 22:33:20
        DateTime newDate2 = DateUtil.offsetDay(date22, 3);
        //常用偏移，结果：2017-03-01 19:33:50
        DateTime newDate3 = DateUtil.offsetHour(date22, -3);

        System.out.println(DateUtil.formatBetween(533514666000L));
        System.out.println(DateUtil.formatBetween(533146000, BetweenFormatter.Level.HOUR));

        //昨天
        DateUtil.yesterday();
        //明天
        DateUtil.tomorrow();
        //上周
        DateUtil.lastWeek();
        //下周
        DateUtil.nextWeek();
        //上个月
        DateUtil.lastMonth();
        //下个月
        DateUtil.nextMonth();




    }
}
